package com.jade.shoesmallinterface.controller;

import com.jade.shoesmallinterface.entity.Result;
import com.jade.shoesmallinterface.entity.UserAddress;
import com.jade.shoesmallinterface.service.UserAddressService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoes/address")
public class UserAddressController {
    @Resource
    private UserAddressService userAddressService;

    /**
     * 根据用户ID查询用户地址信息
     */
    @GetMapping("/selectAddressesByUserId")
    public Result<List<UserAddress>> selectAddressesByUserId(@RequestParam Integer userId) {
        if (userId == null) {
            return Result.error("用户ID不能为空");
        }
        List<UserAddress> addresses = userAddressService.selectAddressesByUserId(userId);
        return Result.success(addresses);
    }

    /**
     * 插入新地址
     */
    @PostMapping("/insertUserAddress")
    public Result<Integer> insertUserAddress(@RequestBody UserAddress userAddress) {
        if (userAddress == null) {
            return Result.error("地址信息不能为空");
        }
        int result = userAddressService.insertUserAddress(userAddress);
        return Result.success(result);
    }
}